#!/bin/bash

container_name="movies-backend"
image_name="${container_name}:v1"
network="movies"

if [[ -z "$(docker network inspect $network 2> /dev/null | grep $network)" ]];then
    docker network create $network
    echo "网络${network}已自动创建"
fi

if [[ -n "$(docker inspect $container_name 2> /dev/null | grep $container_name)" ]];then
    docker stop $container_name
    docker rm $container_name
    docker rmi $image_name
    echo "已删除原来存在的容器和镜像"
fi

cd ~/app/movies-system/backend
docker build ./app -t $image_name
docker run -d -p 7000:7070  -v ./data:/data --network $network --label io.portainer.accesscontrol.teams=members --name $container_name $image_name
echo "自动部署已完成"                        


